#include "EditorOutputAbilityViewModel.h"

#include "Asset/EditorDefaultPackage.h"

#include "Font/FontSubsystem.h"

void REditorOutputAbilityViewModel::BindModel(TSharedObjectPtr<REditorAbilityModel> InModel)
{
    Super::BindModel(InModel);

    OutputModel = InModel;

    Icon = REditorDefaultPackage::Get()->GetIcon(U"CodiconOutput");
    HighlightIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconOutput_Highlight");
    ClearAllIcon= REditorDefaultPackage::Get()->GetIcon(U"CodiconClearAll");

    AutoScrollIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconLock");
    DisabledAutoScrollIcon = REditorDefaultPackage::Get()->GetIcon(U"CodiconUnlock");

    OutputModel->OnLineNumChanged.Bind([this]()
    {
        OnLineNumChanged.ExecuteIfBound();
    });


    Font=RFontApplicationSubsystem::Get() ->GetDefaultFont();
}

TSharedObjectPtr<RTexture2D> REditorOutputAbilityViewModel::GetIcon() const
{
    return Icon;
}

TSharedObjectPtr<RTexture2D> REditorOutputAbilityViewModel::GetHighlightIcon() const
{
    return HighlightIcon;
}

void REditorOutputAbilityViewModel::ClearLines()
{
    OutputModel->ClearLines();
}

void REditorOutputAbilityViewModel::ToggleAutoScroll()
{
    OutputModel->ToggleAutoScroll();
}

TSharedObjectPtr<RTexture2D> REditorOutputAbilityViewModel::GetAutoScrollIcon() const
{
    return IsAutoScroll() ? AutoScrollIcon : DisabledAutoScrollIcon;
}

bool REditorOutputAbilityViewModel::IsAutoScroll() const
{
    return OutputModel->IsAutoScroll();
}

int64_t REditorOutputAbilityViewModel::GetLineNum() const
{
    return OutputModel->GetLineNum();
}

const CString &REditorOutputAbilityViewModel::GetLine(int64_t InIndex)
{
    return OutputModel->GetLine(InIndex);
}

float REditorOutputAbilityViewModel::GetScrollPercent() const
{
    return OutputModel->ScrollPercent;
}

void REditorOutputAbilityViewModel::SetScrollPercent(float InPercent)
{
    OutputModel->ScrollPercent=InPercent;
}

float REditorOutputAbilityViewModel::GetWholeHeight() const
{
    return GetLineNum() * Font->GetLineHeight(FontSize);
}

float REditorOutputAbilityViewModel::GetLineHeight() const
{
    return Font->GetLineHeight(FontSize);
}
